package com.darren.archive.controller;


import com.darren.archive.config.AppConfig;
import com.darren.archive.enums.Gender;
import com.darren.archive.enums.IBaseEnum;
import com.darren.archive.model.SysRoleUser;
import com.darren.archive.model.SysUser;
import com.darren.archive.service.ISysUserService;
import com.darren.archive.utils.DynamicEnumUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import sun.reflect.ConstructorAccessor;
import sun.reflect.FieldAccessor;
import sun.reflect.ReflectionFactory;

import javax.annotation.Resource;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Api(value = "首页接口",tags = "首页接口",description = "首页接口")
@Controller
@Slf4j
public class HomeController {

    @Resource
    private AppConfig appConfig;

    @Resource
    private ISysUserService sysUserService;

    @GetMapping("/home")
    public ModelAndView home(){
        log.info("中华人民共和国");
        log.info(log.getClass().getName());
        log.info(appConfig.getName());
        ModelAndView modelAndView = new ModelAndView("home");
        SysRoleUser sysRoleUser = new SysRoleUser();
        sysRoleUser.setId(10000L);
        modelAndView.addObject("SysUser", sysUserService.getByPrimaryKey(1L));
        return modelAndView;
    }





    @GetMapping("/homepage")
    @ResponseBody
    public SysUser homePage(){

        DynamicEnumUtils.addEnum(Gender.class,"UNKNOWN",new Class[]{Integer.class,String.class},new Object[]{3,"未知"});

        for (Gender gender : Gender.values()) {
            System.out.println(gender.name() +"="+ gender.getCode()+"="+gender.getText());
        }

        SysUser sysUser = new SysUser();

        sysUser.setSex((Gender)IBaseEnum.getByCode(Gender.class,3));

        return sysUser;
//        return sysUserService.getByPrimaryKey(1L);
    }


}
